// pages/authent/authent.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Name: "",
    show: false,
    cellPhone1: "",
    accounts: "",
    Bank: [],
    Bank1: [],
    abouc: "请选择",
    aoe: "请选择",
    Information: [],
    Inform: [],
    token: "",
    Cashback: "自动返显",
    columns: [],
  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },
  onChange1(event) {
    this.setData({
      aoe: event.detail.value
    })
  },
  click() {
    wx.switchTab({
      url: `../keywords/keywords`
    })
  },
  button() {
    var _this = this
    var a
    var b
    _this.data.Inform.forEach((i, l) => {
      if (i.corpName == _this.data.aoe) {
        a = i.corpName,
        b = i.corpKey
      }
    })
    wx.request({
      url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply`,
      data: {
        "name": _this.data.Information.name,
        "phone": _this.data.Information.mobilePhone,
        "idNumber": _this.data.Information.idNumber,
        "branchCode": _this.data.Bank.corpKey,
        "branchName": _this.data.Bank.corpName,
        "subBranchCode": b,
        "subBranchName": a,
      },
      header: {
        'content-type': 'application/json',
        "TOKEN": _this.data.token
      },
      method: "post",
      success: function (data) {
        if (data.data.msg === "申请提交成功!") {
          wx.switchTab({
            url: `../succeed/succeed?name${a}`
          })
        } else {
          wx.switchTab({
            url: `../fail/fail`
          })
        }
      },
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var token = wx.getStorageSync('token')
    var Information = wx.getStorageSync('Information')
    this.setData({
      token: token,
      Information: Information
    })
    var _this = this
    var Bank = wx.getStorageSync('Bank')
    if (Bank == "") {
      this.setData({
        abouc: "请选择"
      })
    } else {
      this.setData({
        Bank: Bank,
        abouc: Bank.corpName,
        Cashback: Bank.corpKey
      })
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/query/sub-branch/list`,
        data: {
          "corpKey": _this.data.Bank.corpKey,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
          "TOKEN": _this.data.token
        },
        method: "post",
        success: function (data) {
          var columns1 = []
          data.data.data.forEach((i, l) => {
            var a = i.corpName
            columns1.push(a)
          })
          _this.setData({
            Inform: data.data.data,
            columns: columns1
          })
        }
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})